package com.csk.zsk.compents.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.csk.zsk.compents.dao.VideoDao;
import com.csk.zsk.compents.dao.VideoItemDao;
import com.csk.zsk.compents.entity.Video;
import com.csk.zsk.compents.entity.VideoItem;
import com.csk.zsk.compents.service.VideoService;

@Service
@Transactional
public class VideoServiceImpl implements VideoService {

	@Autowired
	private VideoDao videoDao;
	@Autowired
	private VideoItemDao videoItemDao;

	@Override
	public void saveVideo(Video video) {
		for (VideoItem videoItem : video.getVideoItemList()) {
			videoItem.setVideo(video);
			videoItemDao.save(videoItem);
		}
		videoDao.save(video);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> getVideoByType(String type, Integer num) {
		return videoDao.getVideoByType(type, num);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> searchVideoByTVName(String tvName) {
		return videoDao.searchVideoByTVName(tvName);
	}

	@Override
	@Transactional(readOnly = true)
	public Video getVideoById(String id) {
		return videoDao.getIdByGetMethod(id);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> getVideoByYear(Integer year, String type) {
		return videoDao.getVideoByYear(year, type);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> getVideoByArea(String area, String type) {
		return videoDao.getVideoByArea(area, type);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> getVideoByYearAndArea(Integer year, String area, String type) {
		return videoDao.getVideoByYearAndArea(year, area, type);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> getVideoByLessThanYear(Integer year, String type) {
		return videoDao.getVideoByLessThanYear(year, type);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> getVideoByLessThanYearAndArea(Integer year, String area, String type) {
		return videoDao.getVideoByLessThanYearAndArea(year, area, type);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> searchVideoByTVNameAndType(String tvName, String type) {
		return videoDao.searchVideoByTVNameAndType(tvName, type);
	}

	@Override
	@Transactional(readOnly = true)
	public List<Video> getVideoByIdList(List<String> idList) {
		return videoDao.getVideoByIdList(idList);
	}

}
